package com.demo.security;

import com.demo.entity.SysUser;
import com.demo.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class AuthUserService implements UserDetailsService {
    @Autowired
    private SysUserMapper mapper;

    @Override
    public AuthUserDetail loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser user = mapper.getByLoginname(s);
        if (user == null) {
            throw new UsernameNotFoundException("未找到用户名");
        }
        AuthUserDetail detail = new AuthUserDetail();
        detail.setUserId(user.getUserId());
        detail.setPassword(user.getLoginPass());
        detail.setUsername(user.getLoginName());
        detail.setRoleId(user.getRoleId());
        detail.setTrueName(user.getTrueName());
        return detail;
    }

}
